#ifndef QSERVER_EVENT_HPP__
#define QSERVER_EVENT_HPP__

namespace qserv
{
    class event
    {
    public:
        enum state_t
        {
            none = 0,
            parent_open,
            parent_read,
            parent_write,
            parent_close,
            child_open,
            child_read,
            child_write,
            child_close,
            user = 1000,
            quote,
        };

        event(std::size_t state = 0,
            std::size_t value = 0,
            char *buf = NULL)
            : state_(state),
            value_(value),
            buf_(new char[value])
        {
            memcpy(buf_, buf, value);
        }

        event(const event& evt)
        {
            if(NULL != buf_)
                delete[] buf_;
            buf_ = new char[evt.value_];
            memcpy(buf_, evt.buf_, evt.value_);
            value_ = evt.value_;
            state_ = evt.state_;
        }

        const event& operator=(const event& evt)
        {
            if(&evt == this)
                return *this;
            if(NULL != buf_)
                delete[] buf_;
            buf_ = new char[evt.value_];
            memcpy(buf_, evt.buf_, evt.value_);
            value_ = evt.value_;
            state_ = evt.state_;
            return *this;
        }

        ~event()
        {
            if (NULL != buf_)
            {
                delete[] buf_;
                buf_ = NULL;
            }
        }

        std::size_t state_;
        std::size_t value_;
        char * buf_;
    };
}
#endif //QSERVER_EVENT_HPP__
